﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class AdminCMS_tab_ArticleBase_List : System.Web.UI.Page
{
    #region 参数
    [RequestQuery.Query(QueryKey = "keyword")]
    public string KeyWord = string.Empty;//关键词
    [RequestQuery.Query(QueryKey = "classid")]
    public int ClassID = 0; //栏目编号    
    #endregion    

    protected void Page_Load(object sender, EventArgs e)
    {
        RequestQuery.SetQueryValues();

        if (!IsPostBack)
        {
            DataTable dt = DataEntity.tab_Class.SelectList("0001", -1, false);
            ddl_class.Items.AddRange(GlocalCache.GetProjectNodes_ListItems(dt, 0));
            ddl_class.Items.Insert(0, new ListItem("-- 全部 --", "0"));

            txt_keyword.Text = KeyWord;
            ddl_class.SelectedValue = ClassID.ToString();

            ProSplitPage1.DataSource = GetPagingData();  //给分页控件附值
            ProSplitPage1.AppendQuery = RequestQuery.GetQueryValues();
            repeater1.DataSource = ProSplitPage1.SplitSource(); //返回拆分结果
            repeater1.DataBind();
        }
    }

    #region 分页方法

    public DataSet GetPagingData()
    {
        StringBuilder sql = new StringBuilder();
        sql.Append(
@"SELECT a.art_PubDate, a.art_FromID, a.art_IssuerID, a.art_IsVideo, a.art_IsMap, a.art_IsElite, a.art_Hits, a.art_Title, a.art_ID,
b.cls_NodeText, c.adm_RealName
FROM ([tab_ArticleBase] a
left join tab_Class b
on a.art_FromID = b.cls_ID)
left join tab_Admin c
on a.art_IssuerID = c.adm_ID
where a.art_FromClass = 0 ");
        /* 追加条件*/
        if (ClassID != 0)
        {
            sql.Append(" AND a.art_FromID = ").Append(ClassID);
        }

        if (KeyWord != string.Empty)
        {
            sql.Append(" AND a.art_Title like '%").Append(KeyWord).Append("%'");
        }

        string Primary = "art_ID"; //主键
        string Orderby = Primary + " DESC";  //排序
        return DataEntity.Common.ExecuteSplitPage(sql.ToString(), Primary, Orderby, ProSplitPage1.MaxRows, ProSplitPage1.PageIndex);
    }
    #endregion
}
